const routerTypeMap = {
  nav: {
    titleKey: "text",
    linkKey: "link",
    childKey: "items",
  },
};
// 根据类型获取路由（默认是sidebar）
const getRouterByType = (type) => {
  function core(arr) {
    if (type && typeObj) {
      arr.forEach((item) => {
        if (item.title) {
          item[typeObj.titleKey] = item.title;
          delete item.title;
        }
        if (item.path) {
          // 如果有中文，需要转译
          item[typeObj.linkKey] = encodeURI(item.path);
          delete item.path;
        }
        if (item.children) {
          item[typeObj.childKey] = item.children;
          delete item.children;
        }

        const child = item[typeObj.childKey];
        if (child && child.length) {
          return core(child);
        }
      });
    }
    return arr;
  }
  const typeObj = routerTypeMap[type];

  const routers = [
    {
      title: "测试菜单",
      path: "/quick",
    }
  ];

  const realRouters = core(routers);
  return realRouters;
};
// 放在此处可以热更新，so 这个热更新真垃圾

module.exports = {
  base: "/blog/",
  title: "xxx的博客", // seo优化的标题
  description: "", // seo优化的description
  sass: { indentedSyntax: true },
  // 主题
  themeConfig: {
    logo: "/assets/img/xxx.jpg", // 导航栏logo
    navbar: true, // 禁用导航栏
    sidebarDepth: 3, // 侧边栏默认展示的层级深度
    searchMaxSuggestions: 10, // 搜索结果数量
    lastUpdated: "更新时间", // string | boolean 最后git提交时间
    smoothScroll: true, // 启用页面滚动效果
    sidebar: getRouterByType("sidebar"), // 侧边栏
    nav: getRouterByType("nav"), // 右上角导航
  },
  // 自定义头部
  head: [
    ["link", { rel: "icon", href: "/assets/img/xxx.ico" }],
    // 禁止移动端缩放
    [
      "meta",
      {
        name: "viewport",
        content:
          "width=device-width, initial-scale=1, user-scalable=no, minimal-ui",
      },
    ],
    ["meta", { name: "author", content: "xxx" }],
    ["meta", { name: "keywords", content: "xxx" }],

    ["link", { rel: "manifest", href: "/manifest.json" }],
    ["meta", { name: "theme-color", content: "#3eaf7c" }],
    ["meta", { name: "apple-mobile-web-app-capable", content: "yes" }],
    [
      "meta",
      { name: "apple-mobile-web-app-status-bar-style", content: "black" },
    ],
    [
      "link",
      { rel: "apple-touch-icon", href: "/icons/xxx192x192.png.png" },
    ],
    // ['link', { rel: 'mask-icon', href: '/icons/safari-pinned-tab.svg', color: '#3eaf7c' }],
    // ['meta', { name: 'msapplication-TileImage', content: '/icons/msapplication-icon-144x144.png' }],
    ["meta", { name: "msapplication-TileColor", content: "#000000" }],
    // 全局脚本
    ["script", { src: "/scripts/global.js" }],
  ],
  plugins: [
    // // 图片预览
    // [
    //   "@vuepress/medium-zoom",
    //   {
    //     selector: "img.zoom-custom-imgs",
    //     // medium-zoom options here
    //     // See: https://github.com/francoischalifour/medium-zoom#options
    //     options: {
    //       margin: 16,
    //     },
    //   },
    // ],
    // // 鼠标点击动效
    // [
    //   "cursor-effects",
    //   {
    //     size: 2, // 粒子大小
    //     shape: "star", // 粒子形状（可选 'star' 和 'circle'）
    //     zIndex: 999999999,
    //   },
    // ],
    // 文章底部更新时间
    [
      "@vuepress/last-updated",
      {
        transformer: (timestamp, lang) => {
          // 不要忘了安装 moment
          const moment = require("moment");
          // moment.locale(lang);
          moment.locale("zh-cn");
          return moment(timestamp).format("LLLL");
        },
      },
    ],
    // 制作pwa，本地暂时失败，发送到线上是成功的
    [
      "@vuepress/pwa",
      {
        serviceWorker: true,
        updatePopup: {
          message: "发现新内容",
          buttonText: "刷新",
        },
      },
    ],
  ],
  // 打包
  configureWebpack: {
    resolve: {
      alias: {
        "@": "path/to",
      },
    },
  },
};
